/**
* This function set default source location_data. we need it in every URL request
*/
var __location_src='';
function __AB_PDoremi_VideoManager_SetDefaultSource(location_src){
	__location_src=location_src;
}

/**
* This function init the Easy Jquery UI
* For the Tree Grid in page Brands Manager
* @author: trungdt
* @since: Sep 27, 2011 
*/
function __AB_PDoremi_VideoManager_Init(selector_name, link_url){
	$("#"+selector_name).datagrid({
		width: 'auto',
		height: 700,
		nowrap: true,
         autoRowHeight:true,
		rownumbers: true,
		animate:true,
		url:video_link_url,
        pageNumber: 1,
        pageSize: 20,
        pagination: 1,
		idField:'id',
        singleSelect: true,
		columns:[[
			{field:'title',title:'Title',width:150},
			{field:'seo_name',title:'Seo Name',width:120},
			{field:'cat_title',title:'Category',width:130},
			{field:'video_type',title:'Type',width:90, 
				formatter:function(value){
					if (value == 0)
						return "Video on Server";
					else
					if (value == 1)
						return "Mp3";
					else
					if (value == 2)
						return "Embed video";
				}
			},
			{field:'postdate_text',title:'Post Date',width:160},
			{field:'views',title:'Views',width:50, align: 'right'}
		]],
		onBeforeLoad:function(row,param){
			$(this).datagrid('options').url = video_link_url;
		}
	});
}

/**
* This function perform the Edit action on the tree grid
* @author: trungdt
* @since Sep 27, 2011
*/
function __AB_PDoremi_VideoManager_Edit(table_selector){
	
	var node = $('#'+table_selector).datagrid('getSelected');
	var url="";
	if (node){
		url="/index.php?module=videomodule&action=video_edit&id="+node.id;
		url+="&src="+__location_src;
		//alert(url);
		window.location=url;
	}
	// 
}

/**
* This function perform the Remove action on the tree grid
* @author: trungdt
* @since Sep 27, 2011
*/
function __AB_PDoremi_VideoManager_Remove(table_selector){
	
	var node = $('#'+table_selector).datagrid('getSelected');
	if (node){
		var temp=Math.random()*9999;
		// call ajax
		jQuery.post("/index.php", {
			module: 'videomodule',
			action: 'video_delete',
			ajax_action: '1',
			id: node.id,
			t: temp
		}, function(data){
			var myObject = eval('(' + data + ')');
			if (myObject.success == 1)
			{
				$("#"+table_selector).datagrid('unselectAll');
				$("#"+table_selector).datagrid('reload');
			}
		});
	}
	// 
}


